﻿<?php
/*
 * @Author Akos Szabo - Axi
 * @Created on Jul 5, 2011
 * @Project: ujej
 * @Description: This is a collection of tools.
 * 
 */
 
//Detect mobile
include_once 'mobile/Mobile_Detect.php';
$detect = new Mobile_Detect();

 
 
 //Global Constants
 
 
 $g_TIMEOUT = 900; //in sec, 15 min
 
 
//Global variables
$ujejId = "";
$isGuest = 1;
$isAdmin = 0;
$sportArray = "";
$umail="";
$g_sessionTimeout;


$topActionDiv="";




function getTopActionDiv( $argType)
{
	global $loginMsg, $umail;
	
$loginDiv = 	"<div id='_1'>	<!-- távtartó -->"	
				."<div id='_login'>"
				."<form action='index.php' method='post'>"
				."<font color='#FF0000'>".$loginMsg."</font>név: <input id='_input' type='text' size='25' name='umail' />"
				."jelszó: <input id='_input' type='password' size='25' name='upw' />"
				."<input id='_login_submit' type='submit' value='Belép' name='submit_login' />"				
				."</form>"				 
				."<a class='_login' href='register.php'>Regisztráció</a>"			
				  ."|" 
				."<a class='_login' href='elfelejtett_jelszo.php'>Elfelejtettem a jelszavam</a>"
			."</div>"
			."</div><!-- _1 -->";

$logoutDiv = 	"<div id='_1_B'>	<!-- távtartó˝ -->"	
				."<div id='_login' style='font-size: 14px;'>"
				."<a class='_login' >".$umail."</a>"
				." | "		 
				."<a class='_login' href='index.php?cmd=logout'>Kilépes</a>"			
			."</div>"
			."</div><!-- _1_B -->";
			
	if($argType == 0) return $loginDiv;
	if($argType == 1) return $logoutDiv;
	
}


function userLogout()
{
	global $oUser, $_SESSION;
	$_SESSION['ujej_timeout'] = time();
	$oUser->logout();
	
}

function isOnMobile()
{
	global $detect;
	return $detect->isMobile();
}

function getMobileType()
{
	global $detect;
	return $detect->getMobileType();
}



function getSportList($argSelected)
{
global $dbh, $sportArray;

	$res = $dbh->do_query("SELECT * FROM sport");
	$sportArray = "''";
	$sportslist = "<select name='sportList' id='sportList' onChange='sportListOnChange()'>";
/*
	if( $argSelected<>"")
	{
		$sportslist = $sportslist . "<option SELECTED value='".$argSelected."'></option>";
	}
*/		
	$sportslist = $sportslist . "<option value='0'></option>";
	if($res > 0)
	{
		while($sor = mysql_fetch_array($dbh->result))
		{
			$sportslist = $sportslist . "<option value='" .$sor['idsport']."'>".$sor['sname']."</option>";
			$sportArray = $sportArray . ",'".$sor['sname']."'";		
		}
		$sportslist = $sportslist . "</select>";
	}
	return  $sportslist;
}


function getAreaList()
{
	global $dbh;
	//Create area list
	$res = $dbh->do_query("SELECT * FROM area");
	$arealist = "<select name='areaList'>";
	if($res > 0)
	{
		while($sor = mysql_fetch_array($dbh->result))
		{
			$arealist = $arealist . "<option value'" .$sor['idarea']."'>".$sor['name']."</option>";		
		}
		$arealist = $arealist . "</select>";
	}
} //end of getAreaList
 
//jogosultsĂˇgokat le kell kĂ©rdezni Ă©s az alapjĂˇn
//guest menu
//user menu
//admin menu 
function getMainMenu()
{
	global $ujejId, $oUser;
	//writeLog("Enter getMMenu");
		$mainpage_mainmeu = "<a title='Haza' class='fomenu' href='index.php'>Fő oldal</a>"
		."__"
		."<a title='Ha szeretnél játszani és keresed a társakat, helyet.' class='fomenu' href='index.php'>Játszanék</a>"
		."__"
		."<a class='fomenu' href=\'index.php\'>Csapattárs</a>"
		."__"
		."<a class='fomenu' href='index.php'>Hely</a>"
		."__"
		."<a class='fomenu' href='index.php'>Lastminute</a>";

	if($ujejId<1)
	{
		$mainpage_mainmeu = $mainpage_mainmeu ."____"
		."<a class='fomenu' href='register.php'>REGISZTRÁCIÓ</a>";
	}

	if($ujejId>0)
	{
		$mainpage_mainmeu = $mainpage_mainmeu ."____"
		."<a class='fomenu' href='profile.php'>ÉnMagam</a>";
		
		if( $oUser->getArgument("userGroup") == $oUser->GROUP_ADMIN)
		{
			$mainpage_mainmeu = $mainpage_mainmeu ."____"
		."<a class='fomenu' href='admin.php'>Admin</a>";
		}
	}

		return $mainpage_mainmeu;
}//end of getMainMenu

function getHomeMenu()
{
	
		$regpage_mainmeu = "<a title='Haza' class='fomenu' href='index.php'>Fő oldal</a>";

		return $regpage_mainmeu;
		
}//end of getRegMenu

function getHTTPHeader()
{
	global $_SERVER;
	$retVal="";
	foreach($_SERVER as $i=>$val)
	{
		$retVal = $retVal . $i . "-" . $val . "\n";
	} 
	return $retVal;
}

function checkRequest()
{
	global $ujejId, $_SESSION, $oUser, $dbh, $umail, $g_TIMEOUT;
	 
///////TEMPORARLY for TEST PURPOSES/////////////
	//Login bkos@ujej.hu constantly	
	$ujejId = $_SESSION['ujej_id']; //"46";
	
	
	
	if($ujejId=="")
	{
		$_SESSION['ujej_id'] = "0";
		$ujejId = "0";
		echo "Nincs user";
	}
	
	
	if( $ujejId>0 )
	{	
		echo "Van user";
		//check if timeout become valid
		$g_sessionTimeout =  $_SESSION['ujej_timeout'];		
		$oUser = new user_handler($dbh, $ujejId);
		$umail = $oUser->getArgument("mail");
		//echo "umail=".$umail;
		$_SESSION['ujej_timeout'] = time()+$g_TIMEOUT;	
	}
	
}



function gtSportLevelDescription()
{
	$level = "";
/*
 1 elvi bajnok - kezdĹ‘, nem prĂłbĂˇltam mĂ©g
 2 udvar bajnok - suliban jĂˇtszottunk pĂˇrszor
 3 lakĂłtĂ¶mb ajnok - nĂ©ha jĂˇtszom
 4 utca bajnok - rendszeresen jĂˇtszom
 5 kerĂĽleti bajnok - kĂ¶rnyezetemben az egyik legjobb vagyok, akĂˇr edzĂ©sekre is jĂˇrok
 6 vĂˇrosi bajnok - amatĹ‘r szinten versenyezhetnĂ©k is, akĂˇr versenyzem is 
 7 megye bajnok - rendszeresen versenyzem
 8 magyar bajnok - jegyzett magyar
 10 vilĂˇg bajnok - kĂĽlfĂ¶ldĂ¶n is jegyzett 
 */
	return $level;
}

//-------------------------------------------------------

$g_logMsg="";
function writeLog($argMsg)
{
	global $g_logMsg; 
	$g_logMsg = $g_logMsg . "\n" . $argMsg;
}


function flushLog()
{
	global $g_logMsg;
	echo "<!-- Log:\n" . $g_logMsg . " -->\n";
}
 
?>
